package hash;

import java.util.HashSet;
import java.util.Set;

/**
 * Created by JiaJia on 2019/5/25 0025.
 * 判断数组是否含有重复元素
 */
public class ContainsDuplicate {
    private static boolean containsDuplicate(int[] nums){
        Set<Integer> set = new HashSet<>();
        for (int num:nums) {
            set.add(num);
        }
        return set.size()<nums.length;
    }

    public static void main(String[] args) {
        int[] nums1={1,2,2,3,4,5,6};
        int[] nums2={1,2,3,4,5,6,7};
        System.out.println(containsDuplicate(nums1));
        System.out.println(containsDuplicate(nums2));
    }
}